#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.8.1
 Author:         myName

 Script Function:
	Template AutoIt script.

#ce ----------------------------------------------------------------------------

Global $harvest_answer[2][2] = [[433,435],[556,435]]
Global $harvest_ask[4] = [517,353,0x001f3c,0x937f61]
;0x6B5A43
;click harvest: 521,406 harvest 1-2

;click harvest: 142,340 harvest 1-1
;color(589,686) = 0xD28730
Func can_harvest($pos)
   Local $p = $winlist[$pos]
   Local $x = $p[0] + $p[2] + $harvest_ask[0]
   Local $y = $p[1] + $p[3] + $harvest_ask[1]
   Local $color = PixelGetColor($x,$y)
   _DebugOut($pos & ": color(" & $x & "," & $y & ") = 0x" & Hex($color,6))
   If $color = $harvest_ask[2] Then
	  Return 0 ; no tryes
   ElseIf $color = $harvest_ask[3] Then
	  Return 1 ; has tryes
   Else
	  Return 2 ; undefined
   EndIf
EndFunc

Func try_harvest($pos, $from = -1)
   If $from < 0 Then
	  For $m = 2 To 0 Step -1
		 For $i = 0 To 14
			If $last_count_result[$i][3] > $m Then
			   Return click_to_point_harvest($pos,$i)
			EndIf
		 Next
	  Next
	  Return -1
   ElseIf $from  > 14 Then
	  Return -1
   Else
	  Return click_to_point_harvest($pos,$from)
   EndIf
   
EndFunc

Func click_to_point_harvest($pos,$i)
   Local $x = $last_count_result[$i][0] + $field[0] + random_shift(2) - 1
   Local $y = $last_count_result[$i][1] + $field[1] + random_shift(2) - 1
   _DebugOut($pos & ": click harvest: " & $i & " (" & $x & "," & $y & ") harvest " & $last_count_result[$i][3] & "-" & $last_count_result[$i][4])
   make_click($pos,$x,$y)
   Return $i
EndFunc

Func agree_harvest($pos,$index = 1)
   make_click($pos,$harvest_answer[$index][0],$harvest_answer[$index][1])
EndFunc
